#pragma once

#include "fxcc/core/graph/common/pch.h"
#include "fxcc/core/graph/common/PositionKey.h"
#include "fxcc/core/graph/common/RotationKey.h"
#include "fxcc/core/graph/common/ScaleKey.h"
#include "fxcc/core/graph/common/Transform.h"
#include "fxcc/core/graph/common/AnimNode.h"

namespace fxcc
{
    namespace graph
    {
        namespace common
        {
            struct FXCC_API Channel : public Base
            {
                std::string m_NodeName;

                double m_Duration{ 20.0f };

                std::vector<PositionKey> m_PositionKeys;

                std::vector<RotationKey> m_RotationKeys;

                std::vector<ScaleKey> m_ScaleKeys;

                glm::ivec3 m_KeyFlag{ 1,1,1 };

                AnimNode* m_Entity { 0 };

                Channel() = default;

                Channel(aiNodeAnim* channel);

                glm::vec3 GetPosition(double ct_time) const;

                glm::quat GetRotation(double ct_time) const;
                
                glm::vec3 GetScale(double ct_time) const;

                int GetPositionIndex(double index) const;
                
                int GetRotationIndex(double index) const;
                
                int GetScaleIndex(double index) const;

                glm::mat4 GetSlerpMatrix(double index) const;

                static void CopyTransformFlag(fxcc::graph::common::Transform& target, const fxcc::graph::common::Transform& source, glm::ivec3 flag)
                {
                    if (flag.x)
                    {
                        target.m_Position = source.m_Position;
                    }
                    if (flag.y) 
                    {
                        target.m_Rotation = source.m_Rotation;
                    }
                    if (flag.z)
                    {
                        target.m_Scale = source.m_Scale;
                    }
                }

                fxcc::graph::common::Transform GetSlerpTransform(double index) const;

                void UpdateTransform(double index)
                {
                    if (m_Entity)
                    {
                        m_Entity->SetTranform(GetSlerpTransform(index));
                    }
                }
                void UpdateTransformAxis(float axis)
                {
                    UpdateTransform(axis * m_Duration);
                }


            };
        }
    }
};